<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Set_Template_Recurring extends Page
{
       public $lbldesc = null;
       public $lbltype = null;
       public $Label4 = null;
       public $Label2 = null;
       public $imgBack = null;
       public $JTJavaScript1 = null;
       public $hiddenStyle = null;
       public $lblTemplate = null;
       public $JTRecurringList = null;
       public $imageAddRecurringTask = null;
       public $lblRecurring = null;
       public $hiddenTemplate = null;
       public $JTSiteTheme1 = null;
       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function imageAddRecurringTaskJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images["imageAddRecurringTask"].src="image/add_new.png"
       <?php

       }

       function imageAddRecurringTaskJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images["imageAddRecurringTask"].src="image/add_new_blue.png"
       <?php

       }

       function Set_Template_RecurringCreate($sender, $params)
       {
       $template_id = $_GET['template_id'];
       $style = $_GET['style'];
       $this->hiddenTemplate->setValue($template_id);
       $this->hiddenStyle->setValue($style);

       $this->imageAddRecurringTask->setLink('set_template_recurring_create.php?template='.$this->hiddenTemplate->getValue().'&style='.$this->hiddenStyle->getValue());
       $this->imgBack->setLink('set_template_list.php');

       $result_tempnum = mysql_query("select * from template_tbl where template_id='".$this->hiddenTemplate->getValue()."'");
       $row_tempnum = mysql_fetch_array($result_tempnum);
       $this->lblRecurring->Caption=$row_tempnum['template_num'];
       $this->lbltype->Caption=$row_tempnum['template_type'];
       $this->lbldesc->Caption=$row_tempnum['description'];
       }

       function JTRecurringListShow($sender, $params)
       {
       $template_id =  $this->hiddenTemplate->getValue();
       $result_recurring = mysql_query("select * from template_recurring_tbl where company_id='".$_SESSION['company_id']."' and template_id='".$template_id."'")or die ('SELECT RECURRING'.mysql_error());
       $arr = array();
       while($row = mysql_fetch_array($result_recurring))
       {
       $recurring_id = $row['id'];
       $template_style = $row['template_style'];

       $sched_by = $row['schedule_by'];

       if($sched_by=='Mileage')
       {
       $due = $row['usage_basis'].' '.'Km';
       }

       if($sched_by=='Hours')
       {
       $due = $row['usage_basis'].' '.'Hours';
       }

       if($sched_by=='Time' || $sched_by=='Date')
       {
       $due = $row['date_basis'];
       }

       $recur = $row['recurring'];
       if($recur=='1')
       {
       $icon = "<img src=image/recur3.png title='Recurring'></img>";
       }
       if($recur=='0')
       {
       $icon = "";
       }

      //$style = $this->hiddenStyle->getValue();
      $recurring = "<a href=set_template_recurring_edit.php?template_id=".$template_id."&recurring=".$recurring_id.">".$sched_by."</a>";
       $tools = "<img onclick=js_deleteRecurring('".$template_id."','".$recurring_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
       //"<a href=template_recurring_delete.php?template=".$template_id."&recurring=".$recurring_id."><img src='image/delete_orange.jpg' title='delete' no border></a>";

       $arr[] = array(
                        'Scheduled by' => $icon.' '.$recurring,
                        'Due' => $due,
                        'Type' => $row['type'],
                        'Task Description' => $row['description'],
                        'Tools' =>$tools
                        );
       }

        $this->JTRecurringList->setCellData($arr);



       }



}

global $application;

global $Set_Template_Recurring;

//Creates the form
$Set_Template_Recurring=new Set_Template_Recurring($application);

//Read from resource file
$Set_Template_Recurring->loadResource(__FILE__);

//Shows the form
$Set_Template_Recurring->show();

?>